<template>
  <j-modal :title="title" :width="width" :visible="visible" :confirmLoading="confirmLoading" switchFullscreen
    @ok="handleOk" @cancel="handleCancel" cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="最高空气温度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kqwda">
              <a-input v-model="model.kqwda" placeholder="请输入最高空气温度"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最低空气温度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kqwdb">
              <a-input v-model="model.kqwdb" placeholder="请输入最低空气温度"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最高空气湿度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kqsda">
              <a-input v-model="model.kqsda" placeholder="请输入最高空气湿度"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最低空气湿度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kqsdb">
              <a-input v-model="model.kqsdb" placeholder="请输入最低空气湿度"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最高光照强度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gzqda">
              <a-input v-model="model.gzqda" placeholder="请输入最高光照强度"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最低光照强度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gzqdb">
              <a-input v-model="model.gzqdb" placeholder="请输入最低光照强度"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否启动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zt">
              <j-switch v-model="model.zt"></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kssj">
              <j-date placeholder="请选择开始时间" v-model="model.kssj" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jssj">
              <j-date placeholder="请选择结束时间" v-model="model.jssj" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>

import { httpAction } from '@/api/manage'

export default {
  name: "ZwglEltqszModal",
  components: {
  },
  props: {
    mainId: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      title: "操作",
      width: 800,
      visible: false,
      model: {
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },

      confirmLoading: false,
      validatorRules: {
      },
      url: {
        add: "/hjyzbj/zwglEltq/addZwglEltqsz",
        edit: "/hjyzbj/zwglEltq/editZwglEltqsz",
      }

    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.$refs.form.clearValidate();
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          this.model['wj'] = this.mainId
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },


  }
}
</script>
